<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>芹菜博客系统</title>
    <link href="/summernotes/bootstrap1.css" rel="stylesheet">
    <link href="/summernotes/summernote.css" type="text/css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="/admin/css/main.css"/>
    <link rel="stylesheet" type="text/css" href="/admin/css/top.css"/>
    <link rel="stylesheet" type="text/css" href="/admin/css/left.css"/>
    <link rel="stylesheet" type="text/css" href="/admin/css/right.css"/>
    <style>
        .demo{
            width: 80%;
            margin: 50px;
        },
        * {
            margin: 0;
            padding: 0;
        }
    </style>
</head>
<body>
<div id="container">
    <div id="header">
        <h1 style="margin-top: -3px;">博客管理系统</h1>
        <div id="login_info">
            欢迎你：<?php
            echo session('admin_name');
            ?>
            <a href="/admin/login/logout/">退出登录</a>
        </div>
    </div>

    <div id="left">
        <ul>
            <li><a href="/admin/category/index/">分类管理</a></li>
            <li><a href="/admin/article/index/">文章管理</a></li>
            <li><a href="/admin/comment/index/">评论管理</a></li>
            <li><a href="/admin/user/index/">用户管理</a> </li>
            <li><a href="/admin/good/index/">点赞管理</a> </li>
            <li><a href="/admin/admin/index/">管理员</a></li>
        </ul>
    </div>

    <div id="right">
    <div id="content">
        <div id="breadcrumb">
            <a href=index.php?c=article&a=index>首页</a> &gt;
            <a href=index.php?c=article&a=index>文章管理</a> &gt;
            <a href="index.php?c=article&a=add">增加文章</a>
        </div>
        <form action="/admin/article/addSave/" method="post">
            <table class="update">
                <tr>
                    <td>文章标题：</td>
                    <td><input type="text" name="article_title"/></td>
                </tr>
                <tr>
                    <td>所属分类：</td>
                    <td>
                        <select name="category_id">
                            <option value="0">请选择分类</option>
                            <?php foreach ($categoryList as $row): ?>
                                <option value="<?php echo $row['category_id']; ?>">
                                    <?php echo $row['category_name'] ?>
                                </option>
                            <?php endforeach; ?>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>文章简介：</td>
                    <td>
                        <textarea name="intro"></textarea>
                    </td>
                </tr>
                <tr>
                    <td>文章封面url地址：</td>
                    <td>
                        <input type="text" name="cover_image">
<!--                        <textarea  class="demo" ></textarea>-->
                    </td>
                </tr>
                <tr>
                    <td>文章内容：</td>
                    <td>
                        <textarea id="summernote" name="content"></textarea>
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <input type="submit" value="提交" class="btn"/>
                        <input type="reset" value="重置" class="btn"/>
                    </td>
                </tr>
            </table>
        </form>
    </div>
</div>

<?php echo \think\facade\View::fetch("public/footer"); ?>
    <script src="/summernotes/jquery2.js" type="text/javascript"></script>
    <script src="/summernotes/bootstrap2.js"></script>
    <script src="/summernotes/summernote.js" type="text/javascript"></script>
    <script src="/summernotes/summernote-zh-CN.js"></script>
    <script type="text/javascript">
        $(document).ready(function() {

            $('#summernote').summernote({
                lang:'zh-CN',
                callbacks: {
                    onImageUpload: function(files) {
                        console.log(files);
                        //上传图片到服务器，使用了formData对象，至于兼容性...据说对低版本IE不太友好
                        var form = document.getElementById("addForm");
                        console.log(form);
                        var formData = new FormData(form);
                        console.log(formData);
                        formData.append('file',files[0]);

                        $.ajax({
                            url : 'https://wzq0307.com/uploaddemo/upload_file.php',//后台文件上传接口
                            type : 'POST',
                            data : formData,
                            processData : false,
                            contentType : false,
                            success : function(data) {
                                console.log(data);
                                // let imgSrc = "http://120.25.225.179/uploaddemo/upload/default.jpeg";
                                // console.log(imgSrc);
                                $('#summernote').summernote('insertImage',data,'img');
                            },
                        });
                    }
                }
            });

        });


    </script>
